import DrawPoint from './plotShapes/DrawPoint.js' //点
import DrawPolyline from './plotShapes/DrawPolyline.js' //线
import DrawCurve from './plotShapes/DrawCurve.js' //曲线
import DrawRectangle from './plotShapes/DrawRectangle.js'
import DrawPolygon from './plotShapes/DrawPolygon.js' //面
import DrawCircle from './plotShapes/DrawCircle.js' //圆
import DrawBillboard from './plotShapes/DrawBillboard.js' //图标
import DrawstraightArrow from './plotShapes/DrawstraightArrow.js' //直线箭头
import DrawAttackArrow from './plotShapes/DrawAttackArrow.js' //攻击箭头
import DrawPincerArrow from './plotShapes/DrawPincerArrow.js' // 钳击箭头
import DrawText from './plotShapes/DrawText.js' // 文字

class plotsUnit {
  constructor(arg) {
    this.viewer = arg.viewer
    this.Cesium = arg.Cesium
    var option = arg
    this._DrawPoint = new DrawPoint(option)
    this._DrawPolyline = new DrawPolyline(option)
    this._DrawCurve = new DrawCurve(option)
    this._DrawRectangle = new DrawRectangle(option)
    this._DrawPolygon = new DrawPolygon(option)
    this._DrawCircle = new DrawCircle(option)
    this._DrawBillboard = new DrawBillboard(option)
    this._DrawstraightArrow = new DrawstraightArrow(option)
    this._DrawAttackArrow = new DrawAttackArrow(option)
    this._DrawPincerArrow = new DrawPincerArrow(option)
    this._DrawText = new DrawText(option)
  }

  //鼠标绘制
  DrawCreate(option) {
    this.destroy()
    switch (option.type) {
      case '点':
        this._DrawPoint.startCreate(option)
        break
      case '线':
        this._DrawPolyline.startCreate(option)
        break
      case '曲线':
        this._DrawCurve.startCreate(option)
        break
      case '多边形':
        this._DrawPolygon.startCreate(option)
        break
      case '矩形':
        this._DrawRectangle.startCreate(option)
        break
      case '圆':
        this._DrawCircle.startCreate(option)
        break
      case '图标':
        this._DrawBillboard.startCreate(option)
        break
      case '直线箭头':
        this._DrawstraightArrow.startCreate(option)
        break
      case '攻击箭头':
        this._DrawAttackArrow.startCreate(option)
        break
      case '钳击箭头':
        this._DrawPincerArrow.startCreate(option)
        break
      case '文字':
        this._DrawText.startCreate(option)
        break
      default:
        break
    }

  }

  //获取绘制数据
  DrawGet(type) {
    var positions = null
    switch (type) {
      case '点':
        positions = this._DrawPoint.getData()
        break
      case '线':
        positions = this._DrawPolyline.getData()
        break
      case '曲线':
        positions = this._DrawCurve.getData()
        break
      case '多边形':
        positions = this._DrawPolygon.getData()
        break
      case '矩形':
        positions = this._DrawRectangle.getData()
        break
      case '圆':
        positions = this._DrawCircle.getData()
        break
      case '图标':
        positions = this._DrawBillboard.getData()
        break
      case '直线箭头':
        positions = this._DrawstraightArrow.getData()
        break
      case '攻击箭头':
        positions = this._DrawAttackArrow.getData()
        break
      case '攻击箭头':
        positions = this._DrawPincerArrow.getData()
        break
      case '文字':
        this._DrawText.getData()
        break
      default:
        break
    }
    return positions
  }

  //数据构建标绘
  LoadCreate(type, data) {
    var entity = null
    switch (type) {
      case '点':
        entity = this._DrawPoint.loadPoint(data)
        break
      case '文字':
        this._DrawText.loadPoint(data)
        break
      case '线':
        entity = this._DrawPolyline.loadPolyline(data)
        break
      case '曲线':
        entity = this._DrawCurve.loadCurveline(data)
        break
      case '多边形':
        entity = this._DrawPolygon.loadPolygon(data)
        break
      case '矩形':
        entity = this._DrawRectangle.loadRectangle(data)
        break
      case '圆':
        entity = this._DrawCircle.loadCicle(data)
        break
      case '图标':
        entity = this._DrawBillboard.loadBillboard(data)
        break
      case '直线箭头':
        entity = this._DrawstraightArrow.loadStraightArrow(data)
        break
      case '攻击箭头':
        entity = this._DrawAttackArrow.loadStraightArrow(data)
      case '攻击箭头':
        entity = this._DrawPincerArrow.loadPincerArrow(data)
      default:
        break
    }
    return entity
  }

  destroy() {
    console.log('销毁');
    this._DrawPoint.destroy()
    this._DrawText.destroy()
    this._DrawPolyline.destroy()
    this._DrawCurve.destroy()
    this._DrawPolygon.destroy()
    this._DrawRectangle.destroy()
    this._DrawCircle.destroy()
    this._DrawBillboard.destroy()
    this._DrawstraightArrow.destroy()
    this._DrawAttackArrow.destroy()
    this._DrawPincerArrow.destroy()
  }

  //清空
  clear() {
    this.destroy()
    this._DrawPoint.clear()
    this._DrawText.clear()
    this._DrawPolyline.clear()
    this._DrawCurve.clear()
    this._DrawRectangle.clear()
    this._DrawPolygon.clear()
    this._DrawCircle.clear()
    this._DrawBillboard.clear()
    this._DrawstraightArrow.clear()
    this._DrawAttackArrow.clear()
    this._DrawPincerArrow.clear()
  }
  //选择清除
  selectrClear() {
    const that = this
    this.destroy()
    this.handler = new this.Cesium.ScreenSpaceEventHandler(this.viewer.cesiumViewer.scene.canvas)
    this.handler.setInputAction(function (evt) { //注册单机选择物体删除事件
      const pick = that.viewer.cesiumViewer.scene.pick(evt.position)
      if (that.Cesium.defined(pick)) {
        that.viewer.dataSourceDisplay._defaultDataSource.entities.remove(pick.id)
      }
    }, this.Cesium.ScreenSpaceEventType.LEFT_CLICK)
    this.handler.setInputAction(function (evt) { //右击移除当前删除事件
      that.handler.removeInputAction(that.Cesium.ScreenSpaceEventType.LEFT_CLICK)
      that.handler.removeInputAction(that.Cesium.ScreenSpaceEventType.RIGHT_CLICK)
    }, this.Cesium.ScreenSpaceEventType.RIGHT_CLICK)
  }
}


export default plotsUnit
